<?php
namespace app\api\model;
use think\Model;
class Xhmimagui extends Model
{
    public function index()
    {   
       
    }

    public function insert($uid)
    {
    	$data=[
           'uid'=>$uid,
           'zhuangtai'=>1,
           'mima'=>mt_rand(111111,999999),
    	];
    	 //return $id=model('xhmimagui')->insertGetId($data);

       //查询xhmimagui表是否有zhuangtai为-1的记录(数组)，有的话用$data更新数组的第一项，没有的话直接插入数据
       $res = model('xhmimagui')->where('zhuangtai',-1)->select();
       if ($res) {
            //更新
            $count = model('xhmimagui')->where('bianhao',$res[0]->bianhao)->update($data);
            return $res[0]->bianhao; 
       }else{
            //插入
            return $id = model('xhmimagui')->insertGetId($data);
       }
    }
}